package com.it.orderservice.controller;


import com.it.commonutils.R;
import com.it.orderservice.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author test.java
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/orderservice/paylog")
@CrossOrigin
public class PayLogController {
    @Autowired
    private PayLogService payLogService;
    //生成微信支付二维码
    @GetMapping("createNative/{orderNo}")
    public R createNative(@PathVariable String orderNo){
        //返回包括二维码地址 还有其他信息
        Map map=payLogService.createNative(orderNo);
        System.out.println("****返回二维码map集合"+map);
        return R.ok().data(map);
    }

    //查看订单支付状态
    @GetMapping("queryPayStatus/{orderNo}")
    public R queryPayStatus(@PathVariable String orderNo){
        //查看支付状态
        Map<String,String>map=payLogService.queryPayStatus(orderNo);
        System.out.println("****查询订单状态"+map);
        if(map==null){
            return R.error().message("支付出错");
        }
        if(map.get("trade_state").equals("SUCCESS")){
            //更新支付状态
            payLogService.updtaOrdersStatus(map);
            return R.ok().message("支付成功");
        }
        return R.ok().code(25000).message("支付中");
    }
}

